/**
 * @file Acceptor.hh
 * @author zziywang (zziywang@163.com)
 * @brief { life is too short to learn cpp! }
 * @version 1.0
 * @date 2022-05-06
 *
 * @copyright Copyright (c) 2022
 *
 */

#pragma once

#include "InetAddress.hh"
#include "Socket.hh"

namespace snow
{

class Acceptor
{
public:
    Acceptor(const string &ip, unsigned short port);
    explicit Acceptor(unsigned short port);
    Acceptor(const struct sockaddr_in addr);

    void ready(); // setreuse + bind + listen
    int accept(); // peerfd

    void setPortReuse(bool flag);
    void setAddrReuse(bool flag);

    // v2新增
    int getSockFd() const; // 获取服务器sockfd，注册进epoll

private:
    void bind();
    void listen(int backlog);

private:
    InetAddress addr_;
    Socket listenSock_; // 服务器负责监听的线程
};

} // namespace snow